package com.kn.sys;

import com.kn.sys.dao.PermissionDao;
import com.kn.sys.dto.IdsDto;
import com.kn.sys.mapper.RolePermissiomMapper;
import com.kn.sys.model.RolePermissiom;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import javax.management.relation.RoleResult;
import java.util.ArrayList;

@SpringBootTest
public class testDao {
    @Resource
    private RolePermissiomMapper rolePermissiomMapper;
    @Resource
    private PermissionDao permissionDao;

    @Test
    public void testSingle(){
        long l = System.currentTimeMillis();
        RolePermissiom rolePermissiom = new RolePermissiom();
        rolePermissiom.setPermid(1L);
        rolePermissiom.setRoleid(1L);
        for(int i=0;i<100000;i++){
            rolePermissiomMapper.insertSelective(rolePermissiom);
        }
        System.out.println(System.currentTimeMillis()-l);
    }
    @Test
    public void testBatch(){
        long l = System.currentTimeMillis();
        IdsDto idsDto = new IdsDto();
        idsDto.setId1(1L);
        idsDto.setId2(1L);
        ArrayList<IdsDto> list = new ArrayList<>();
        for(int i=0;i<1000000;i++){
            list.add(idsDto);
            if(i%5000==0){
                permissionDao.savePermission(list);
                list.clear();
            }
        }
        permissionDao.savePermission(list);
        System.out.println(System.currentTimeMillis()-l);
    }
}
